package com.xjh.him.common;

import com.xjh.him.domain.UserDO;

import javax.servlet.http.HttpServletRequest;


public class LoginUser {
    private static final String ENV_USER = "user";

    private static HttpServletRequest request;

    /**
     * 设置请求对象
     * @param request
     */
    public static void setRequest(HttpServletRequest request, UserDO userDO) {
        LoginUser.request = request;
        LoginUser.request.setAttribute(ENV_USER, userDO);
    }

    /**
     * 获取登录用户
     * @return
     */
    public static UserDO getLoginUser() {
        if (request == null) {
            return null;
        }
        return (UserDO) request.getAttribute(ENV_USER);
    }

    /**
     * 清空
     */
    public static void clear() {
        if (request != null) {
            request.setAttribute(ENV_USER, null);
            request = null;
        }
    }
}
